/* 
 * Copyright 2010 HIT-CIR (HIT Center for Information Retrieval). 
 * 
 * author: chuter
 * mail:   lliu@ir.hit.edu.cn
 */
package nlpeap.config;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

/**
 * 
 * @author chuter
 *
 */
public class ConfigProperties {
    /** IMPLEMENTATION DETAIL: the singleton instance */
    private static ConfigProperties singleton;
    private final Properties _prop;
    
    private static final String PROP_FILE = "./config/config.properties";
    /** the male_dic file path */
    private static final String MALEDIC_PATH = "database.maledic";
    /** the female_dic file path */
    private static final String FEMALEDIC_PATH = "database.femaledic";
    /** the gender_dic file path, this dictionary stores the 
     * 	probability of the last word of a name for male */
    private static final String GENDERDIC_PATH = "database.genderdic";
    /** the alias dictionary path */
    private static final String ALIASDIC_PATH = "database.alias";
    /** whether use the parser */
    private static final String PARSER = "PARSER";
    /** the tags for Person Names */
    private static final String PERSON_NAME_TAG = "PERSON_NAME_TAG";
    /** the classifier threshold */
    private static final String CLASSIFY_THRESHOLD = "CLASSIFY_THRESHOLD";
    /** whether use Dependency Parser in parsing the plain text */
    private static final String USE_DEP_PARSER = "USE_DEP_PARSER";
    /** whether debug, if that the system print more information */
    private static final String DEBUG = "DEBUG";
    
    /** get the instance of ConfigProperties */
    public static synchronized ConfigProperties getInstance()
    {
        if (singleton == null) { singleton = new ConfigProperties(); }
        return singleton;
    }
    
    /** Creates a new instance of ConfigProperties */
    private ConfigProperties() {
        // loads the properties
        _prop = new Properties();
        try {
            final FileInputStream in = new FileInputStream(PROP_FILE);
            _prop.load(in);
            in.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
    
    /** Retrieve a specified property in </code>String form */
    public String getProperty(String key)
    { return _prop.getProperty(key); }
    
    /** get the path of the male dictionary */
    public String getMaleDicPath()
    { return _prop.getProperty(MALEDIC_PATH, "./database/maledic"); }
    
    /** get the path of the female dictionary */
    public String getFemaleDicPath()
    { return _prop.getProperty(FEMALEDIC_PATH, "./database/femaledic"); }
    
    public String getGenderDicPath()
    { return _prop.getProperty(GENDERDIC_PATH, "./database/genderdic"); }
    
    /** get the parser class name, if it hasn't been set, return null */
    public String getParserClassName()
    { return _prop.getProperty(PARSER, null); }
    
    public String getAliasDicPath()
    { return _prop.getProperty(ALIASDIC_PATH, "./database/aliasmap"); }
    
    /** get the regular expression to match the tags for Person Names */
    public String getPersonNameTagRegxp()
    { return _prop.getProperty(PERSON_NAME_TAG, "(nh|Na|Nh)"); }
    
    /** get the classifier threshold */
    public double getClassifyThreshold() { 
    	try {
    		return Double.valueOf(_prop.getProperty(CLASSIFY_THRESHOLD, "0.50005")); 
    	} catch (NumberFormatException e) {
    		e.printStackTrace();
    		throw new RuntimeException("Error: ", e);
    	}
    }
    
    /** get whether to use Dependency Parser */
    public boolean useDepParser() {
    	String use_depParser = _prop.getProperty(USE_DEP_PARSER, "false");
    	if (use_depParser.equalsIgnoreCase("false"))
    		return false;
    	else
    		return true;
    }
    
    public boolean isDebug() {
    	if (_prop.getProperty(DEBUG, "true").equalsIgnoreCase("true"))
    		return true;
    	else
    		return false;
    }
    
    public static void main(String[] argv) {
    	ConfigProperties cp = ConfigProperties.getInstance();
    	System.out.println(cp.getFemaleDicPath());
    }
        
    
}
